
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/http/dio_service.dart';
import 'package:flutter_ncsjqz_getx/model/base_entity.dart';
import 'package:flutter_ncsjqz_getx/model/login_entity.dart';
import 'package:flutter_ncsjqz_getx/util/get_user_util.dart';
import 'package:flutter_ncsjqz_getx/util/toast_util.dart';
import 'package:get/get.dart';
import 'package:package_get/base_logic.dart';

import 'email_password_view.dart';
///
/// <summary>
/// todo: 
/// author：zwb
/// dateTime： 2021/11/9 10:51
/// filePath： lib/page/my/email_phone_pwd/email_password_logic.dart
/// desc:
/// <summary>
///
class EmailPasswordLogic extends BaseLogic {
  bool setNewPassword = false;
  EPW? type;
  TextEditingController textEditingControllerTel = TextEditingController();
  TextEditingController textEditingControllerCode = TextEditingController();
  TextEditingController textEditingControllerPwd = TextEditingController();
  TextEditingController textEditingControllerPwd1 = TextEditingController();
  TextEditingController textEditingControllerEmail = TextEditingController();

  // 获取自己的用户信息
  LoginData? loginData = getUserUtil();
  /// todo：切换设置密码
  setNewPwd(){
    setNewPassword = true;
    update();
  }


  getSms() async{
    // 验证码 1注册，2登录，3找回密码 ， 4绑定手机号
    BaseEntity baseEntity = await DioService<BaseEntity>().getSmsCode({
      "telPhone": textEditingControllerTel.value.text,
      "smsCodeType": 4
    });
    if(baseEntity.code == 0) {
      sendCode();
      toast("发送成功");
    }
  }

  getEmail() async{
    BaseEntity baseEntity = await DioService<BaseEntity>().getMailboxSmsCode({
      "mailbox": textEditingControllerEmail.value.text,
    });
    if(baseEntity.code == 0) {
      sendCode();
      toast("发送成功");
    }
  }

  setEmail() async{
    BaseEntity baseEntity = await DioService<BaseEntity>().bindMailbox({
      "mailbox": textEditingControllerEmail.value.text,
      "smSCode": textEditingControllerCode.value.text,
    });
    if(baseEntity.code == 0) {
      toast("绑定成功");
      Get.back();
    }
  }
}
